/**
 * Created by lijing on 2016-06-22.
 */
$.validator.setDefaults({
    submitHandler: function () {
        savePub();
    }
});
$(document).ready(function () {
    validate();
    $("#industryCategoryName").click(function () {
        $("#industryCategoryName").cate({
            title: "行业类别",
            url: G_Path.path + "/sys/tag/category",
            param: {"dictCode": "INDUSTRYCATEGORY"},
            liveSearch: false,
            "id": "industryCategory",
            "name": "industryCategoryName"
        });
    });
    $("#companyCategoryName").click(function () {
        $("#companyCategoryName").cate({
            title: "公司类型",
            url: G_Path.path + "/sys/tag/category",
            param: {"dictCode": "COMPANYCATEGORY"},
            liveSearch: false,
            "id": "companyCategory",
            "name": "companyCategoryName"
        });
    });
    $("#companySizeName").click(function () {
        $("#companySizeName").cate({
            title: "公司规模",
            url: G_Path.path + "/sys/tag/category",
            param: {"dictCode": "PERSONNELSCALE"},
            liveSearch: false,
            "id": "companySize",
            "name": "companySizeName"
        });
    });
});
function validate() {
    //设置默认属性
    $("#mainForm").validate({
        rules: {
            name: {
                required: true,
                minlength: 1
            },
            industryCategoryName: {
                required: true,
                minlength: 1
            },
            companyCategoryName: {
                required: true,
                minlength: 1
            },
            website: {
                required: true,
                minlength: 1
            }

        },
        messages: {
            name: {
                required: "请输入公司名称",
                minlength: ""
            },
            industryCategoryName: {
                required: "请选择行业类别",
                minlength: ""
            },
            companyCategoryName: {
                required: "请选择公司类型",
                minlength: ""
            },
            website: {
                required: "请输入公司官网",
                minlength: ""
            }
        }
    });
}
function savePub() {
    $.post(G_Path.path + "/user/company/save", $("#mainForm").serialize(), function (text) {
        var data = $.parseJSON(text);
        if (data.status) {
            if ("view" == status) {
                history.back();
            } else {
                window.close();
            }
        } else {
            showDialogMessage(data.msg);
        }
    });
}